package com.kexio.pay.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 支付服务配置属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.pay")
public class PaymentProperties {
    
    /**
     * 是否启用支付服务
     */
    private boolean enabled = false;
    
    /**
     * 默认支付提供商
     */
    private String defaultProvider = "wechat";
    
    /**
     * 支付超时时间 (分钟)
     */
    private int paymentTimeout = 30;
    
    /**
     * 订单号前缀
     */
    private String orderNoPrefix = "PAY";
    
    /**
     * 微信支付配置
     */
    private WechatConfig wechat = new WechatConfig();
    
    /**
     * 支付宝配置
     */
    private AlipayConfig alipay = new AlipayConfig();
    
    /**
     * 银联支付配置
     */
    private UnionPayConfig unionpay = new UnionPayConfig();
    
    /**
     * 回调配置
     */
    private CallbackConfig callback = new CallbackConfig();
    
    /**
     * 安全配置
     */
    private SecurityConfig security = new SecurityConfig();
    
    /**
     * 监控配置
     */
    private MonitorConfig monitor = new MonitorConfig();
    
    public static class WechatConfig {
        private String appId;
        private String mchId;
        private String apiKey;
        private String apiV3Key;
        private String certPath;
        private String privateKeyPath;
        private String serialNo;
        private String notifyUrl;
        private String returnUrl;
        private boolean sandbox = false;
        
        // Getters and Setters
        public String getAppId() { return appId; }
        public void setAppId(String appId) { this.appId = appId; }
        
        public String getMchId() { return mchId; }
        public void setMchId(String mchId) { this.mchId = mchId; }
        
        public String getApiKey() { return apiKey; }
        public void setApiKey(String apiKey) { this.apiKey = apiKey; }
        
        public String getApiV3Key() { return apiV3Key; }
        public void setApiV3Key(String apiV3Key) { this.apiV3Key = apiV3Key; }
        
        public String getCertPath() { return certPath; }
        public void setCertPath(String certPath) { this.certPath = certPath; }
        
        public String getPrivateKeyPath() { return privateKeyPath; }
        public void setPrivateKeyPath(String privateKeyPath) { this.privateKeyPath = privateKeyPath; }
        
        public String getSerialNo() { return serialNo; }
        public void setSerialNo(String serialNo) { this.serialNo = serialNo; }
        
        public String getNotifyUrl() { return notifyUrl; }
        public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; }
        
        public String getReturnUrl() { return returnUrl; }
        public void setReturnUrl(String returnUrl) { this.returnUrl = returnUrl; }
        
        public boolean isSandbox() { return sandbox; }
        public void setSandbox(boolean sandbox) { this.sandbox = sandbox; }
    }
    
    public static class AlipayConfig {
        private String appId;
        private String privateKey;
        private String publicKey;
        private String alipayPublicKey;
        private String signType = "RSA2";
        private String charset = "UTF-8";
        private String format = "JSON";
        private String notifyUrl;
        private String returnUrl;
        private boolean sandbox = false;
        
        // Getters and Setters
        public String getAppId() { return appId; }
        public void setAppId(String appId) { this.appId = appId; }
        
        public String getPrivateKey() { return privateKey; }
        public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
        
        public String getPublicKey() { return publicKey; }
        public void setPublicKey(String publicKey) { this.publicKey = publicKey; }
        
        public String getAlipayPublicKey() { return alipayPublicKey; }
        public void setAlipayPublicKey(String alipayPublicKey) { this.alipayPublicKey = alipayPublicKey; }
        
        public String getSignType() { return signType; }
        public void setSignType(String signType) { this.signType = signType; }
        
        public String getCharset() { return charset; }
        public void setCharset(String charset) { this.charset = charset; }
        
        public String getFormat() { return format; }
        public void setFormat(String format) { this.format = format; }
        
        public String getNotifyUrl() { return notifyUrl; }
        public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; }
        
        public String getReturnUrl() { return returnUrl; }
        public void setReturnUrl(String returnUrl) { this.returnUrl = returnUrl; }
        
        public boolean isSandbox() { return sandbox; }
        public void setSandbox(boolean sandbox) { this.sandbox = sandbox; }
    }
    
    public static class UnionPayConfig {
        private String merId;
        private String certPath;
        private String certPassword;
        private String rootCertPath;
        private String middleCertPath;
        private String notifyUrl;
        private String returnUrl;
        private boolean sandbox = false;
        
        // Getters and Setters
        public String getMerId() { return merId; }
        public void setMerId(String merId) { this.merId = merId; }
        
        public String getCertPath() { return certPath; }
        public void setCertPath(String certPath) { this.certPath = certPath; }
        
        public String getCertPassword() { return certPassword; }
        public void setCertPassword(String certPassword) { this.certPassword = certPassword; }
        
        public String getRootCertPath() { return rootCertPath; }
        public void setRootCertPath(String rootCertPath) { this.rootCertPath = rootCertPath; }
        
        public String getMiddleCertPath() { return middleCertPath; }
        public void setMiddleCertPath(String middleCertPath) { this.middleCertPath = middleCertPath; }
        
        public String getNotifyUrl() { return notifyUrl; }
        public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; }
        
        public String getReturnUrl() { return returnUrl; }
        public void setReturnUrl(String returnUrl) { this.returnUrl = returnUrl; }
        
        public boolean isSandbox() { return sandbox; }
        public void setSandbox(boolean sandbox) { this.sandbox = sandbox; }
    }
    
    public static class CallbackConfig {
        /**
         * 是否启用异步处理
         */
        private boolean asyncEnabled = true;
        
        /**
         * 最大重试次数
         */
        private int retryMaxTimes = 3;
        
        /**
         * 重试间隔 (毫秒)
         */
        private long retryInterval = 60000;
        
        /**
         * 回调超时时间 (秒)
         */
        private int timeout = 10;
        
        /**
         * 是否验证IP白名单
         */
        private boolean verifyIp = false;
        
        /**
         * IP白名单
         */
        private String[] allowedIps = {};
        
        // Getters and Setters
        public boolean isAsyncEnabled() { return asyncEnabled; }
        public void setAsyncEnabled(boolean asyncEnabled) { this.asyncEnabled = asyncEnabled; }
        
        public int getRetryMaxTimes() { return retryMaxTimes; }
        public void setRetryMaxTimes(int retryMaxTimes) { this.retryMaxTimes = retryMaxTimes; }
        
        public long getRetryInterval() { return retryInterval; }
        public void setRetryInterval(long retryInterval) { this.retryInterval = retryInterval; }
        
        public int getTimeout() { return timeout; }
        public void setTimeout(int timeout) { this.timeout = timeout; }
        
        public boolean isVerifyIp() { return verifyIp; }
        public void setVerifyIp(boolean verifyIp) { this.verifyIp = verifyIp; }
        
        public String[] getAllowedIps() { return allowedIps; }
        public void setAllowedIps(String[] allowedIps) { this.allowedIps = allowedIps; }
    }
    
    public static class SecurityConfig {
        /**
         * 是否启用签名验证
         */
        private boolean verifySignature = true;
        
        /**
         * 是否启用HTTPS
         */
        private boolean requireHttps = true;
        
        /**
         * 签名算法
         */
        private String signAlgorithm = "RSA2";
        
        /**
         * 加密密钥
         */
        private String encryptKey;
        
        // Getters and Setters
        public boolean isVerifySignature() { return verifySignature; }
        public void setVerifySignature(boolean verifySignature) { this.verifySignature = verifySignature; }
        
        public boolean isRequireHttps() { return requireHttps; }
        public void setRequireHttps(boolean requireHttps) { this.requireHttps = requireHttps; }
        
        public String getSignAlgorithm() { return signAlgorithm; }
        public void setSignAlgorithm(String signAlgorithm) { this.signAlgorithm = signAlgorithm; }
        
        public String getEncryptKey() { return encryptKey; }
        public void setEncryptKey(String encryptKey) { this.encryptKey = encryptKey; }
    }
    
    public static class MonitorConfig {
        /**
         * 是否启用监控
         */
        private boolean enabled = true;
        
        /**
         * 慢查询阈值 (毫秒)
         */
        private long slowQueryThreshold = 3000;
        
        /**
         * 是否记录详细日志
         */
        private boolean detailedLog = false;
        
        /**
         * 统计时间窗口 (分钟)
         */
        private int statsWindow = 60;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public long getSlowQueryThreshold() { return slowQueryThreshold; }
        public void setSlowQueryThreshold(long slowQueryThreshold) { this.slowQueryThreshold = slowQueryThreshold; }
        
        public boolean isDetailedLog() { return detailedLog; }
        public void setDetailedLog(boolean detailedLog) { this.detailedLog = detailedLog; }
        
        public int getStatsWindow() { return statsWindow; }
        public void setStatsWindow(int statsWindow) { this.statsWindow = statsWindow; }
    }
    
    // Main class getters and setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public String getDefaultProvider() { return defaultProvider; }
    public void setDefaultProvider(String defaultProvider) { this.defaultProvider = defaultProvider; }
    
    public int getPaymentTimeout() { return paymentTimeout; }
    public void setPaymentTimeout(int paymentTimeout) { this.paymentTimeout = paymentTimeout; }
    
    public String getOrderNoPrefix() { return orderNoPrefix; }
    public void setOrderNoPrefix(String orderNoPrefix) { this.orderNoPrefix = orderNoPrefix; }
    
    public WechatConfig getWechat() { return wechat; }
    public void setWechat(WechatConfig wechat) { this.wechat = wechat; }
    
    public AlipayConfig getAlipay() { return alipay; }
    public void setAlipay(AlipayConfig alipay) { this.alipay = alipay; }
    
    public UnionPayConfig getUnionpay() { return unionpay; }
    public void setUnionpay(UnionPayConfig unionpay) { this.unionpay = unionpay; }
    
    public CallbackConfig getCallback() { return callback; }
    public void setCallback(CallbackConfig callback) { this.callback = callback; }
    
    public SecurityConfig getSecurity() { return security; }
    public void setSecurity(SecurityConfig security) { this.security = security; }
    
    public MonitorConfig getMonitor() { return monitor; }
    public void setMonitor(MonitorConfig monitor) { this.monitor = monitor; }
}
